
#include "kodes.h"
#include "Local8.h"
#include <stdlib.h>

#include <boost/assert.hpp>

// se 0 redonis, do EOF aux alia erraro
wchar_t ElLocal8::doni()
{
  unsigned char b = doniBajton();
  if (b <= 0x7f)
    return b;

//#ifdef _WIN32_WINNT
  wchar_t res;
  if (mbtowc(&res, (char*)&b, 1) < 0)
    throw runtime_error("Can't encode char");
  return res;
}


void AlLocal8::meti(wchar_t c)
{
  BOOST_ASSERT(c);
  if (static_cast<unsigned long>(c) <= 0x7f)
    metiBajton(static_cast<unsigned char>(c));
  else
  {
    int mbc = wctob(c);
    if (mbc <= 0 || mbc >= 0xff)
      throw runtime_error("Can't encode char");
    metiBajton(static_cast<unsigned char>(mbc));
  }
}
